
local EventBus = require "3rd/events"

-- base controller(mediator)
BaseController = {mControllerName = "BaseController"};

BaseController.transform = nil;
BaseController.gameObject = nil;

function BaseController:New(o)
    o = o or {};
    setmetatable(o, self);
    self.__index = self;
    return o;
end

-- @ start this controller working
function BaseController:Awake()
	-- create view: async or sync
    -- todo
end

-- @ when skin created, start init view
function BaseController:OnViewCreated(go)
	self.gameObject = go;
	--self.transform = go.transform;

	self:InitView();
end

-- @ init view
-- @ override by sub class
function BaseController:InitView()
	-- todo
end

-- @ add event listener
function BaseController:InstallEventListener(isInstall)
	-- body
end

-- @eventName such as property change
-- @... other params
function BaseController:DispatchEvent(eventName, ...)
	-- body
	EventBus.Brocast(eventName, ...);
end

-- @eventName sub as other model change
-- @handler when event fired, call handler
function BaseController:AddEventListener(eventName, handler)
	-- body
	EventBus.AddListener(eventName, handler);
end

-- @eventName which has been listener
-- @handler will be removed from listener
function BaseController:RemoveListener(eventName, handler)
	-- body
	EventBus.RemoveListener(eventName, handler);
end

-- @ dispose this controller
function BaseController:Dispose()
	-- todo
	self:InstallEventListener(false);
end